package exam.service.impl;

import com.github.pagehelper.PageHelper;
import exam.bean.Student;
import exam.dao.StudentDao;
import exam.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements IStudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    public List<Student> selectStudent(int pageNum, int pageSize) {

        //将参数传给这个方法就可以实现物理分页了，非常简单。
        PageHelper.startPage(pageNum, pageSize);
        return studentDao.selectStudent(null);
    }

    @Override
    public int insertStu(Student student){

        return studentDao.insertStu(student);
    }

    @Override
    public int updateStudent(Student student) {



        return studentDao.updateStudent(student);
    }

    @Override
    public int deleteStudent(int id) {
        return studentDao.deleteStudent(id);
    }

    @Override
    public Student selectStudentSingle(Map<String, Object> map) {

        /**
         * selectStudent 早dao里面查询
         * get(0)  代表查询List数组出来的第一条数据
         * a[0]  a[1]  a[2]   这个是数组的角标
         */
        return studentDao.selectStudent(map).get(0);
    }
}
